<template>
     <h2>用户投资赎回</h2>
     <table>
           <tr>
              <td>项目名称</td>
              <td>{{info.I_Name}}</td>
           </tr>
           <tr>
              <td>项目投资总金额</td>
              <td>{{info.I_Budget}}</td>
           </tr>
           <tr>
              <td>用户已投金额</td>
              <td>{{info.UI_Money}}</td>
           </tr>
           <tr>
              <td>赎回金额</td>
              <td>
                 <input type="text"  v-model="UR_money"/>
              </td>
           </tr>
           <tr>
             <td colspan="2" style="text-align: center;">
             <input type="button" value="确认赎回" @click="SaveData" />
            </td>
           </tr>
     </table>
</template>


<script setup lang="ts">
import { ref,onMounted} from 'vue';

import {useRoute,useRouter} from 'vue-router';

const route = useRoute();

const router = useRouter();

alert(route.params.UIid);

import axios from 'axios';

const UR_money = ref("");

const info = ref({
    I_Name:"",
    I_Budget:0,
    UI_Money:0
})

onMounted(()=>{
    LoadData();
})

const LoadData =()=>{
    axios({
        url:"https://localhost:44337/api/Invests/GetUserInvestInfo",
        method:"get",
        params:{
            Uid:route.params.UIid
        }
    }).then(res=>{
        console.log(res.data);
        info.value.I_Name= res.data[0].I_Name;
        info.value.I_Budget= res.data[0].I_Budget;
        info.value.UI_Money= res.data[0].UI_Money;
    }).catch
    (err=>{
        console.log(err);
    })
}

//完成用户投资赎回
const SaveData =()=>{
     axios({
        url:"https://localhost:44337/api/Invests/AddUserInvestRedeemInfo",
        method:"post",
        data:{
            UI_Id:route.params.UIid,
            UIR_Money:UR_money.value
        }
     }).then(res=>{
            if(res.data>0)
            {
                alert("用户赎回成功");
                router.push("/ShowUserInvestRedeem")
            } else
            {
                alert("用户赎回失败");
            }
     }).catch
     (err=>{
        console.log(err);
     })
}
</script>
